import EditProductTask from '../../model/EditProductTask'
import EditProductLog from '../../model/EditProductLogs'
export default class EditProductLogsController {
    static async createLog(ctx) {
        // console.log('ctx.request', ctx.request)
        const { data } = ctx.request.body
        console.log(data)
        data.shopId = ctx.request.header.shop_id
        const result = await EditProductTask.create(data)
        ctx.body = result._id
    }
    static async addLog(ctx) {
        const { setAddnewLog, TaskId, productId, status, code, type } = ctx.request.body
        if (!TaskId || !productId || !status || !code || !type) {
            ctx.body = '参数错误'
            return
        }
        const result = await EditProductLog.create({
            TaskId,
            productId,
            statusName: status,
            code,
            type,
            setAddnewLog,
            shopName: ctx.request.header.shop_name,
            shopId: ctx.request.header.shop_id
        })
        ctx.body = result._id
        // const result = await EditProductTaskSchema.findByIdAndUpdate(TaskId, setAddnewLog)
    }
    static async getTask(ctx) {
        console.log('ctx.request', ctx.query)
        const { page, pageSize, name, taskId, startTime, endTime, shop_id } = ctx.query
        const findObj = {
            shopId: ctx.request.header.shop_id
        }
        console.log('findObj', findObj)

        const result = await EditProductTask
            .find(findObj)
            .sort({ createTime: -1 })
            .limit(pageSize * 1)
            .skip((page - 1) * pageSize)
        ctx.body = {
            list: result,
            total: await EditProductTask.countDocuments(findObj)
        }

        // ctx.body = await EditProductTask.find()
    }
    static async getPrdLogs(ctx) {
        const { page, pageSize, name, taskId, startTime, endTime, shop_id } = ctx.query
        const findObj = {
            shopId: ctx.request.header.shop_id,
            TaskId: taskId
        }
        console.log('findObj', findObj)

        const result = await EditProductLog
            .find(findObj)
            .sort({ createTime: -1 })
            .limit(pageSize * 1)
            .skip((page - 1) * pageSize)
        ctx.body = {
            list: result,
            total: await EditProductLog.countDocuments(findObj)
        }
    }

}